import 'package:flutter/material.dart';

// 折叠头部+tabbar
class Page9 extends StatefulWidget {
  const Page9({super.key});

  @override
  State<Page9> createState() => _Page9State();
}

class _Page9State extends State<Page9> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3,
      child: Scaffold(
        body: NestedScrollView(
          headerSliverBuilder: (context, innerBoxIsScrolled) {
            return [
              SliverAppBar(
                title: Text('折叠头部 + TabBar'),
                pinned: true, // 滑动时固定在顶部
                floating: false,
                expandedHeight: 200.0,
                flexibleSpace: FlexibleSpaceBar(
                  background: Image.network(
                    'https://picsum.photos/400/200',
                    fit: BoxFit.cover,
                  ),
                ),
                bottom: TabBar(
                  tabs: [
                    Tab(text: '页面 1'),
                    Tab(text: '页面 2'),
                    Tab(text: '页面 3'),
                  ],
                ),
              ),
            ];
          },
          body: TabBarView(
            children: [
              _buildListView('页面 1 内容'),
              _buildListView('页面 2 内容'),
              _buildListView('页面 3 内容'),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildListView(String label) {
    return ListView.builder(
      padding: EdgeInsets.zero, // 避免内边距影响滑动联动
      itemCount: 30,
      itemBuilder: (context, index) {
        return ListTile(title: Text('$label - 项目 $index'));
      },
    );
  }
}
